package com.yxzx.ebs.controller;

import com.yxzx.common.YxzxResult;
import com.yxzx.ebs.util.JwtUtils;
import com.yxzx.ebs.util.NoneAuth;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/user")
@Slf4j
public class UserController {

    @GetMapping("login")
    @NoneAuth
    public YxzxResult doLogin(String username,String password){
        log.info("执行登录功能.........");
        //调用数据库的用户名进行登录验证
        String jwtToken = JwtUtils.getJwtToken(username, password);

        return YxzxResult.ok().data("token",jwtToken);
    }


    @PostMapping("login")
    public YxzxResult login(){
        log.info("执行登录功能.........");
        return YxzxResult.ok().data("token","admin");
    }

    @GetMapping("info")
    public YxzxResult info(){
        log.info("执行获取用户信息功能.........");
        //"data":{"roles":["admin"],"name":"admin",
        // "avatar":"https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"}}
        return YxzxResult.ok().data("roles","[\"admin\"]")
                              .data("name","admin")
                              .data("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
    }
}
